package hello;

import java.util.List;

import javax.inject.Inject;

import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.api.PagedList;
import org.springframework.social.facebook.api.Post;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/")
public class HelloController {

    private Facebook facebook;
//TESTE
    @Inject
    public HelloController(Facebook facebook) {
        this.facebook = facebook;
        
    }

    @RequestMapping(method=RequestMethod.GET)
    public String helloFacebook(Model model) {
    	
        if (!facebook.isAuthorized()) {
            return "redirect:/connect/facebook";
        }
        
        
        model.addAttribute(facebook.userOperations().getUserProfile());
        PagedList<Post> homeFeed = facebook.feedOperations().getHomeFeed();
        model.addAttribute("feed", homeFeed);

        
        
        
        List<String> friendIds = facebook.friendOperations().getFriendIds();
        System.out.println("friendIds="+friendIds.toString());
        
        System.out.println("facebook_id="+ facebook.userOperations().getUserProfile().getId());




        return "hello";
    }
    
    public void showFeeds() {

        System.out.println("POSTS-2-***************");
        PagedList<Post> homeFeed = facebook.feedOperations().getHomeFeed();
        homeFeed =  facebook.feedOperations().getFeed("1379413749015737");

        for (Post post : homeFeed) {
        	
        	System.out.println("post="+ post.getMessage());
		}
    
        
        System.out.println("POSTS-1-***************");


        homeFeed =  facebook.feedOperations().getFeed("728851463852354");
        for (Post post : homeFeed) {
        	
        	System.out.println("post="+ post.getMessage());
		}

    }
    

}